import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/checkpoint/checkpoint_prepare_game_gridview.dart';
import 'package:flutter_eve_plugin/constants/font_family.dart';
import 'package:flutter_eve_plugin/constants/font_weight.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/checkpoint/user_card.dart';
import 'package:flutter_eve_plugin/pages/ye_xiu/checkpoint/actions.dart';
import 'package:flutter_eve_plugin/store/main.dart';
import 'package:flutter_eve_plugin/store_vm/app_vm.dart';
import 'package:flutter_eve_plugin/store_vm/ye_xiu/checkpoint/main.dart';
import 'package:flutter_eve_plugin/store_vm/ye_xiu/main.dart';
import 'package:flutter_eve_plugin/utils/image_util.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';
import 'package:flutter_eve_plugin/utils/toast_util.dart';
import 'package:flutter_redux/flutter_redux.dart';

class CheckpointPrepareGameFooterWidget extends StatelessWidget {
  final List<CardList> data;
  final CardList info;
  const CheckpointPrepareGameFooterWidget({Key key, this.data, this.info})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, AppStateViewModel>(converter: (store) {
      return AppStateViewModel(
          state: store.state,
          yeXiuStateViewModel: YeXiuStateViewModel(checkpointStateViewModel:
              CheckpointStateViewModel(fightFunc: (stageId) {
            List<String> list = [info?.card?.cardId ?? ''];
            store.state.yeXiuState.checkpointState.selectMap?.forEach((k, v) {
              data?.forEach((item) {
                if (v == item?.card?.cardId) {
                  list.add(item?.card?.cardId ?? '');
                }
              });
            });
            store.dispatch(
                fight(context: context, stageId: stageId, team: list));
          })));
    }, builder: (context, vm) {
      var selectMap = vm.state.yeXiuState.checkpointState.selectMap;
      var stageInfo = vm.state.yeXiuState.checkpointState.checkpointStageInfo;
      bool enBtn = true;
      selectMap.forEach((key, value) {
        if (value != null) {
          enBtn = false;
        }
      });
      return Container(
        width: setRatio(375),
        height: setRatio(203),
        color: Color(0x4F000000),
        margin: EdgeInsets.only(top: setRatio(20)),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            CheckpointPrepareGameGridViewWidget(data: data),
            Container(
              width: setRatio(345),
              height: setRatio(1),
              margin: EdgeInsets.only(left: setRatio(15), right: setRatio(15)),
              color: Color(0x1FF7F9FC),
            ),
            Container(
              height: setRatio(73),
              width: setRatio(345),
              margin: EdgeInsets.only(
                left: setRatio(15),
                right: setRatio(15),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Container(
                    width: setRatio(110),
                    height: setRatio(24),
                    decoration: BoxDecoration(
                        color: Color(0x6F000000),
                        borderRadius: BorderRadius.circular(setRatio(5))),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        Text(
                          '消耗体力',
                          style: TextStyle(
                              color: Color(0xbFFFFFFF),
                              fontFamily: FontFamily.PINGFANG,
                              fontWeight: FontWeightCustom.PF_Medium,
                              fontSize: setTextSp(12)),
                        ),
                        Image.asset(
                          imageUtilYeXiu(
                              'main/icon_nav_right_physical_strength@3x'),
                          width: setRatio(17),
                          height: setRatio(17),
                        ),
                        Text(
                          '${stageInfo?.stageBasics?.configInfo?.vitality ?? 0}',
                          style: TextStyle(
                              color: Color(0xFFB29AFC),
                              fontFamily: FontFamily.PINGFANG,
                              fontWeight: FontWeightCustom.PF_Medium,
                              fontSize: setTextSp(12)),
                        ),
                      ],
                    ),
                  ),
                  GestureDetector(
                    onTap: () {
                      if (enBtn) {
                        Toast.showYX(context, '最少配置1张最多配置4张');
                      } else {
                        vm.yeXiuStateViewModel.checkpointStateViewModel
                            .fightFunc(
                                stageInfo.stageBasics.configInfo.stageId);
                      }
                    },
                    child: Container(
                      width: setRatio(160),
                      height: setRatio(47),
                      decoration: BoxDecoration(
                          image: DecorationImage(
                              image: AssetImage(enBtn
                                  ? imageUtilYeXiu(
                                      'checkpoint/icon_dialog_btn_enavailable@3x')
                                  : imageUtilYeXiu(
                                      'checkpoint/icon_dialog_btn_available@3x')))),
                      child: Center(
                        child: Text('前往挑战',
                            style: TextStyle(
                                color: Color(0xFFFFFFFF),
                                fontFamily: FontFamily.PINGFANG,
                                fontWeight: FontWeightCustom.PF_Medium,
                                fontSize: setTextSp(17))),
                      ),
                    ),
                  )
                ],
              ),
            )
          ],
        ),
      );
    });
  }
}
